home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / dnet / dshterm1_0.lha / lib / st / textmessage.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-04  |  2.0 KB  |  61 lines

  1. /* Small library of routines to manage text messages */
  2.  
  3. #include <exec/types.h>
  4. #include <exec/memory.h>
  5. #include <proto/exec.h>
  6. #include <proto/dos.h>
  7. #include <st/textmessage.h>
  8. #include <st/st_proto.h>
  9.  
  10. /*********************************************************/
  11.  void TextMessageReply(struct TextMessage **txtmsg)
  12. /*********************************************************
  13.      Safely reply or free a text message structure
  14.              and the associated string
  15.  NOTE: pass a pointer to the pointer to the text message
  16.  since this routine needs to NULLify the pointer itself
  17. **********************************************************/
  18. {
  19.     if(*txtmsg != NULL) {
  20.         SafeFreeString0(&((*txtmsg)->String));
  21.         if(TMREPLYPORT(*txtmsg))
  22.             ReplyMsg((struct Message *)(*txtmsg));
  23.         else FreeMem((*txtmsg), sizeof(struct TextMessage));
  24.         (*txtmsg) = NULL;
  25.     }
  26. }
  27.  
  28.  
  29. /*********************************************************/
  30.  void  TextMessageInitReply(struct TextMessage *txtmsg)
  31. /*********************************************************
  32.   Initialize the reply string part of the text message
  33. **********************************************************/
  34. {
  35.     AllocString0(&(txtmsg->RepString),0);    /* 0 reply string */
  36. }
  37.  
  38. /*********************************************************/
  39.  void TextMessageCleanup(struct MsgPort *ourport)
  40. /*********************************************************
  41.      Cleanup any pending text messages on the port
  42. **********************************************************/
  43. {
  44. struct TextMessage *currtxtmsg;
  45.     if(!ourport) return;
  46.     Forbid();
  47.     while (currtxtmsg = (struct TextMessage *)GetMsg(ourport))
  48.                                 TextMessageReply(&currtxtmsg);
  49.     DeletePort(ourport);
  50.     Permit();
  51. }
  52.  
  53. /*********************************************************/
  54. void TextMessageSafeCleanup(struct MsgPort **ourport)
  55. /*********************************************************
  56.      Cleanup any pending text messages on the port
  57. **********************************************************/
  58. { TextMessageCleanup(*ourport); *ourport = NULL; }
  59.  
  60.  
  61.